#define NO_FLOAT
//#include <a_samp>
#include <a_callbacks>
#include <a_players>

/*
#define MAX_PLAYER_NAME 24
#define MAX_PLAYERS 500


//native IsPlayerConnected(playerid);
native SendPlayerMessageToPlayer(playerid, senderid, const message[]);
native GetPlayerName(playerid, const name[], len);
//native CallRemoteFunction(const function[], const format[], {Float,_}:...);
native GetPVarInt(playerid, const varname[]);

native GetPlayerColor(playerid);
native GetPlayerMoney(playerid);



forward OnFilterScriptInit();
forward OnPlayerConnect(playerid);
forward OnPlayerDisconnect(playerid, reason);
forward OnPlayerCommandText(playerid, cmdtext[]);
forward OnPlayerSpawn(playerid);
*/
native printf(const format[], {Float,_}:...);
native strcmp(const string1[], const strign2[], bool:ignorecase=false, length=cellmax);
#include <adminsys>

#tryinclude num_players


static bool:cmdShow[MAX_PLAYERS];
static bool:iscmdshow;

static pname[MAX_PLAYERS][MAX_PLAYER_NAME];
static bool:ispadm[MAX_PLAYERS];

public OnFilterScriptInit()
{
	iscmdshow = false;
}

public OnPlayerConnect(playerid)
{
	GetPlayerName(playerid, pname[playerid], MAX_PLAYER_NAME);
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	cmdShow[playerid] = false;
	ispadm[playerid] = false;
	CheckCmdShow();
	return 1;
}

public OnPlayerSpawn(playerid)
{
	ispadm[playerid] = IsPlayerExAdmin(playerid);
	// log
	printf("[spawn] [%s]: color: %x%x money: %d vw: %d", pname[playerid],
		(GetPlayerColor(playerid) >> 16) & 0xffff, GetPlayerColor(playerid) & 0xffff,
		GetPlayerMoney(playerid), GetPlayerVirtualWorld(playerid));
	return 1;
}


public OnPlayerRequestClass(playerid, classid)
{
	//printf("[classel] [%s]: class: %d skin: %d", pname[playerid], classid, GetPlayerSkin(playerid));
	return 1;
}

public OnPlayerRequestSpawn(playerid)
{
	printf("[reqspawn] [%s]: skin: %d", pname[playerid], GetPlayerSkin(playerid));
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	//if(CallRemoteFunction("IsPlayerInDuel","i",playerid)) return CallRemoteFunction("DuelOff","i",playerid);

	/****/
	printf("[cmd] [%s]: %s", pname[playerid], cmdtext);
	if(iscmdshow)
		for(new i=0;i<MAX_PLAYERS;i++) if(cmdShow[i]) SendPlayerMessageToPlayer(i, playerid, cmdtext);

	/****/
	if(!ispadm[playerid]) return 0;
	if(strcmp("/cmdshow on", cmdtext,true)==0)
	{
		iscmdshow = true;
		return(cmdShow[playerid] = true);
	}

	if(strcmp("/cmdshow off", cmdtext,true)==0)
	{
		cmdShow[playerid] = false;
		CheckCmdShow();
		return true;
	}
	return 0;
}


stock CheckCmdShow()
{
	for(new i=0; i < MAX_PLAYERS; i++)
		if(cmdShow[i]) return false;
	iscmdshow = false;
	return true;
}

